//
//  HotCollectionViewCell.m
//  礼物说
//
//  Created by dllo on 16/4/25.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "HotCollectionViewCell.h"

@interface HotCollectionViewCell ()

@property (nonatomic, retain) BaseImageView *imgView;
@property (nonatomic, retain) BaseView *view;

/** 价格*/
@property (nonatomic, retain) BaseLabel *price;
/** 喜欢的人数*/
@property (nonatomic, retain) BaseLabel *likeCount;
/** 图片*/
@property (nonatomic, retain) BaseImageView *likeImg;
@property (nonatomic, copy) NSString *pirceStr;

@end

@implementation HotCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)dealloc {
    [_pirceStr release];
    [_model release];
    [_imgView release];
    [_likeCount release];
    [_likeImg release];
    [_price release];
    [_title release];
    [_view release];
    [super dealloc];
}

- (void)setModel:(HotModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [_imgView sd_setImageWithURL:[NSURL URLWithString:_model.cover_image_url] placeholderImage:PLACEHOLDER_IMAGE];
    _title.text = _model.name;
    
    self.pirceStr = [NSString stringWithFormat:@"%@", _model.price];
    _price.text = _pirceStr;
    
    _likeCount.text = [_model.favorites_count stringValue];
}

- (void)setGiftModel:(GifContentsModel *)giftModel {
    if ( _giftModel != giftModel) {
        [_giftModel release];
        _giftModel = [giftModel retain];
    }
    [_imgView sd_setImageWithURL:[NSURL URLWithString:_giftModel.cover_image_url] placeholderImage:[UIImage imageNamed:@"jiazai.jpg"]];
    _title.text = _giftModel.name;
    
    self.pirceStr = [NSString stringWithFormat:@"￥%@", _giftModel.price];
    
    _price.text = _pirceStr;
    
    _likeCount.text = [_giftModel.favorites_count stringValue];
}

- (void)createCell {
    
    self.view = [[BaseView alloc] init];
    [self.contentView addSubview:_view];
    [_view release];
    
    self.imgView = [[BaseImageView alloc] init];
    [self.contentView addSubview:_imgView];
    [_imgView release];
    
    self.title = [[BaseLabel alloc] init];
    [self.contentView addSubview:_title];
    [_title release];
    
    self.price = [[BaseLabel alloc] init];
    [self.contentView addSubview:_price];
    [_price release];
    
    self.likeCount = [[BaseLabel alloc] init];
    [self.contentView addSubview:_likeCount];
    [_likeCount release];
    
    self.likeImg = [[BaseImageView alloc] init];
    [self.contentView addSubview:_likeImg];
    [_likeImg release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    
    _view.frame = self.contentView.frame;
    
    _imgView.frame = CGRectMake(0, 0, kWIDTHCELL, kWIDTHCELL);
    
    _title.frame = CGRectMake(kWIDTHS(5), self.imgView.frame.size.height + kWIDTHS(5), kWIDTHCELL, kHEIGHTS(50));
    _title.numberOfLines = 2;
    
    _price.frame = CGRectMake(kWIDTHS(5), kHEIGHTCELL - kWIDTHS(25), kWIDTHS(80), kHEIGHTS(30));
    /**颜色 */
    _price.textColor = [UIColor redColor];
    
    /** 喜欢 图片*/
    _likeImg.frame = CGRectMake(kWIDTHCELL - kWIDTHS(70), kHEIGHTCELL - kHEIGHTS(22), kWIDTHS(15), kHEIGHTS(15));
    _likeImg.image = [UIImage imageNamed:@"heart_32px_1175797_easyicon.net.png"];
    
    /** 喜欢 人数*/
    _likeCount.frame = CGRectMake(kWIDTHCELL - kWIDTHS(50), kHEIGHTCELL - kWIDTHS(30), kWIDTHS(50), kWIDTHS(30));
    /**颜色 */
    _likeCount.textColor = [UIColor grayColor];
}

@end
